/**
 * @Author ZhangGJ
 * @Date 2021/11/14 09:50
 */
#ifndef CPP_IN_ACTION_FRIEND_CURRENCY_H
#define CPP_IN_ACTION_FRIEND_CURRENCY_H

#include <iostream>

enum SignType
{
    plus, minus
};

class Currency
{
    friend std::ostream &operator<<(std::ostream &, const Currency &);

public:

    explicit Currency(SignType theSign = plus, unsigned long theDollars = 0,
                      unsigned int theCents = 0);

    ~Currency() = default;;

    void setValue(SignType, unsigned long, unsigned int);

    void setValue(double);

    SignType getSign() const
    {
        if (amount < 0)
        {
            return minus;
        }
        else
        {
            return plus;
        }
    }

    unsigned long getDollars() const
    {
        if (amount < 0)
        {
            return (-amount) / 100;
        }
        else
        {
            return amount / 100;
        }
    }

    unsigned int getCents() const
    {
        if (amount < 0)
        {
            return -amount - getDollars() * 100;
        }
        else
        {
            return amount - getDollars() * 100;
        }
    }

    Currency operator+(const Currency &) const;

    Currency &operator+=(const Currency &x)
    {
        amount += x.amount;
        return *this;
    }

    void output(std::ostream &) const;

private:
    long amount;
};


#endif //CPP_IN_ACTION_FRIEND_CURRENCY_H
